package com.zhiyou100.review.day019.homework;

import cn.hutool.core.util.RandomUtil;

/**
 * @packageName: Homework1 分别使用继承Thread和实现Runnable的方式  实现三个线程 分别打印数字 、大写、小写
 * @className: com.zhiyou100.review.day019.homework
 * @Description: TODO june 30,2020 作业
 * @author: yang
 * @date: 6/30/20
 */
public class Homework1 {
    public static void main(String[] args) {
        PrintMethod number = new PrintMethod("数字", '0', '9');
        PrintMethod capital = new PrintMethod("大写字母", 'A', 'Z');
        PrintMethod lowercase = new PrintMethod("小写字母", 'a', 'z');

        number.start();
        capital.start();
        lowercase.start();


        PrintMethod1 number1 = new PrintMethod1('0', '9');
        PrintMethod1 capital1 = new PrintMethod1('A', 'Z');
        PrintMethod1 lowercase1 = new PrintMethod1('a', 'z');
        Thread number1Thread = new Thread(number1, "数字");
        Thread capital1Thread = new Thread(capital1, "大写");
        Thread lowercase1lowercase1 = new Thread(lowercase1, "小写");

        number1Thread.start();
        capital1Thread.start();
        lowercase1lowercase1.start();

    }

}

class PrintMethod1 implements Runnable {
    private int start;
    private int end;

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public PrintMethod1(int start, int end) {
        this.start = start;
        this.end = end;
    }

    @Override
    public void run() {
        System.out.println(new PrintMethod().printOne(start, end));
    }
}

class PrintMethod extends Thread {

    /**
     * @Description: TODO 根据传入的 start，和 end 打印一个字符
     * @name: printOne
     * @param: [start, end]
     * @return: char
     * @date: 6/30/20 19:21
     * @author: yang
     */
    char printOne(int start, int end) {
        return (char) RandomUtil.randomInt(start, end + 1);
    }

    private int start;
    private int end;

    public PrintMethod() {
    }

    public PrintMethod(String name, int start, int end) {
        super(name);
        this.start = start;
        this.end = end;
    }

    public PrintMethod(int start, int end) {
        this.start = start;
        this.end = end;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    @Override
    public void run() {
        System.out.println(this.getName() + printOne(getStart(), getEnd()));
    }
}

